<HTML>
<HEAD>
<TITLE>
IBeanWrapper.cpp
</TITLE>
</HEAD>
<BODY>
<PRE>
<font color="green">/*
* Copyright 2006 the original author or authors.
* 
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 
*      http://www.apache.org/licenses/LICENSE-2.0
* 
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/</font>

<font color="blue">#include</font> <font color="maroon">"ValueWrapper.h"</font>
<font color="blue">#include</font> <font color="maroon">"IBeanWrapper.h"</font>
<font color="blue">#include</font> <font color="maroon">"LocalLibrary.h"</font>
<font color="blue">#include</font> <font color="maroon">"AutumnException.h"</font>

<font color="blue">using</font> <font color="blue">namespace</font> std;

<font color="blue">namespace</font> Autumn<font color="black">{</font>

string IBeanWrapper<font color="black">:</font><font color="black">:</font>getConArgTypes<font color="black">(</font><font color="blue">const</font> string<font color="black">&</font> ConMethod, <font color="blue">int</font> num<font color="black">)</font><font color="blue">const</font>
<font color="black">{</font>
    string types;

    <font color="blue">int</font> rtn <font color="black">=</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>getParamTypes<font color="black">(</font>ConMethod, types, num<font color="black">)</font>;
    <font color="blue">if</font><font color="black">(</font> rtn <font color="black">)</font>
        <font color="blue">throw</font> MissDefinitionEx<font color="black">(</font><font color="maroon">"IBeanWrapper"</font>, 
                <font color="maroon">"getConArgTypes"</font>, 
                <font color="maroon">"Getting bean["</font> <font color="black">+</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>BeanName <font color="black">+</font> <font color="maroon">"] constructor-arg types failed!"</font><font color="black">)</font>;

    <font color="blue">return</font> types;
<font color="black">}</font>

<font color="blue">int</font> IBeanWrapper<font color="black">:</font><font color="black">:</font>getBeanPropertyType<font color="black">(</font><font color="blue">const</font> <font color="blue">char</font><font color="black">*</font> <font color="blue">name</font>, string<font color="black">&</font> type<font color="black">)</font><font color="blue">const</font>
<font color="black">{</font>
    string method <font color="black">=</font> string<font color="black">(</font><font color="maroon">"set"</font><font color="black">)</font> <font color="black">+</font> <font color="blue">name</font>;
    <font color="blue">int</font> rtn <font color="black">=</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>getParamTypes<font color="black">(</font>method, type, <font color="maroon">1</font><font color="black">)</font>;
    <font color="blue">if</font><font color="black">(</font> <font color="maroon">0</font> <font color="black">=</font><font color="black">=</font> rtn<font color="black">)</font>
        <font color="green">// erase '|'</font>
        type <font color="black">=</font> type.substr<font color="black">(</font><font color="maroon">0</font>, type.length<font color="black">(</font><font color="black">)</font> <font color="maroon">-1</font> <font color="black">)</font>;
    <font color="blue">return</font> rtn;
<font color="black">}</font>

<font color="blue">bool</font> IBeanWrapper<font color="black">:</font><font color="black">:</font>deleteBean<font color="black">(</font><font color="black">)</font>
<font color="black">{</font>
    <font color="blue">if</font><font color="black">(</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>getBean<font color="black">(</font><font color="black">)</font> <font color="black">=</font><font color="black">=</font> NULL <font color="black">)</font>
        <font color="blue">return</font> <font color="blue">true</font>;
    
    string method <font color="black">=</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>getDestroyMethod<font color="black">(</font><font color="black">)</font>;
    <font color="blue">if</font><font color="black">(</font> <font color="black">!</font>method.empty<font color="black">(</font><font color="black">)</font> <font color="black">)</font><font color="black">{</font>
        <font color="blue">if</font><font color="black">(</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>execVoidMethod<font color="black">(</font>method, NULL, <font color="maroon">0</font><font color="black">)</font> <font color="black">&#60;</font> <font color="maroon">0</font> <font color="black">)</font> <font color="black">{</font>
            <font color="blue">throw</font> MissDefinitionEx<font color="black">(</font><font color="maroon">"IBeanWrapper"</font>, 
                    <font color="maroon">"deleteBean"</font>, 
                    <font color="maroon">"Executing destory-method ["</font> <font color="black">+</font> method <font color="black">+</font> <font color="maroon">"] of bean ["</font> <font color="black">+</font> 
                    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>BeanName <font color="black">+</font> <font color="maroon">"] failed!"</font><font color="black">)</font>;
        <font color="black">}</font>
    <font color="black">}</font>
    
    method <font color="black">=</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>getDeleteMethod<font color="black">(</font><font color="black">)</font>;
    <font color="blue">if</font><font color="black">(</font> <font color="black">!</font>method.empty<font color="black">(</font><font color="black">)</font> <font color="black">)</font> <font color="black">{</font>
        <font color="blue">void</font><font color="black">*</font> p <font color="black">=</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>getBean<font color="black">(</font><font color="black">)</font>;
        <font color="blue">if</font><font color="black">(</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>execVoidMethod<font color="black">(</font>method, <font color="black">&</font>p, <font color="maroon">1</font><font color="black">)</font> <font color="black">&#60;</font> <font color="maroon">0</font> <font color="black">)</font> <font color="black">{</font>
            <font color="blue">throw</font> MissDefinitionEx<font color="black">(</font><font color="maroon">"IBeanWrapper"</font>, 
                    <font color="maroon">"deleteBean"</font>, 
                    <font color="maroon">"Executing delete-method ["</font> <font color="black">+</font> method <font color="black">+</font> <font color="maroon">"] of bean ["</font> <font color="black">+</font> 
                    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>BeanName <font color="black">+</font> <font color="maroon">"] failed!"</font><font color="black">)</font>;
        <font color="black">}</font>
        <font color="blue">return</font> <font color="blue">true</font>;
    <font color="black">}</font>
    <font color="blue">else</font>
        <font color="blue">return</font> <font color="blue">false</font>;
<font color="black">}</font>

<font color="green">/** 
 * Destructor
 */</font>
IBeanWrapper<font color="black">:</font><font color="black">:</font>~IBeanWrapper<font color="black">(</font><font color="black">)</font>
<font color="black">{</font>
    AutumnLog<font color="black">:</font><font color="black">:</font>getInstance<font color="black">(</font><font color="black">)</font><font color="black">-</font><font color="black">&#62;</font>debug<font color="black">(</font><font color="maroon">"IBeanWrapper-&#62;~IBeanWrapper ["</font> <font color="black">+</font> 
            <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>getBeanName<font color="black">(</font><font color="black">)</font> <font color="black">+</font> <font color="maroon">"]"</font><font color="black">)</font>;
    
    <font color="blue">for</font><font color="black">(</font><font color="blue">int</font> i<font color="black">=</font><font color="maroon">0</font>; i<font color="black">&#60;</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>Parameters.size<font color="black">(</font><font color="black">)</font>; i<font color="black">+</font><font color="black">+</font><font color="black">)</font>
        <font color="blue">delete</font> <font color="black">(</font>ValueWrapper<font color="black">*</font><font color="black">)</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>Parameters<font color="black">[</font>i<font color="black">]</font>;

    AutumnLog<font color="black">:</font><font color="black">:</font>getInstance<font color="black">(</font><font color="black">)</font><font color="black">-</font><font color="black">&#62;</font>debug<font color="black">(</font><font color="maroon">"IBeanWrapper-&#62;~IBeanWrapper return"</font><font color="black">)</font>;
<font color="black">}</font>

<font color="green">/** register local function for local library */</font>
<font color="blue">void</font> registerLocalFunction<font color="black">(</font><font color="blue">const</font> <font color="blue">char</font><font color="black">*</font> <font color="blue">name</font>, <font color="blue">void</font><font color="black">*</font> f<font color="black">)</font>
<font color="black">{</font>
    Autumn<font color="black">:</font><font color="black">:</font>LocalLibrary<font color="black">:</font><font color="black">:</font>getInstance<font color="black">(</font><font color="black">)</font><font color="black">-</font><font color="black">&#62;</font>addFunction<font color="black">(</font><font color="blue">name</font>, f<font color="black">)</font>;
<font color="black">}</font>

<font color="black">}</font> <font color="green">// End namespace Autumn</font>


</PRE>
</BODY>
</HTML>
